<?php
require_once(dirname(__FILE__)."/../core/safeParam.php");

$pizzas_option = $database->select("SELECT * FROM pizza_feasts where rid  = ".ARID."");
$pizza_options = $pizzas_option[0];

echo '
  <style type="text/css">
    input{border:1px solid #CCCCCC; width:200px}
    textarea{border:1px solid #CCCCCC; width:200px}
  </style>
  <span class="button"><a href="?edit=pizza-feasts" >View Pizzas</a> </span>
  <span class="button"><a href="?edit=pizza-feasts&pizza-options=1" >Edit Pizza Options</a></span> 
  <span class="button"><a href="?edit=pizza-feasts&add=1" >Add a pizza</a> </span>
 ';
if($_GET['pizza-options'] == 1){
        if($pizza_options['id'] == ""){
          $method = 'add';	
        }else{
          $method = 'edit';	
        }
?>
	
	
<form action="../functions/pizza-feasts.php?function=<?php echo $method; ?>-pizza" method="post">
 <input type="hidden" name="rid" value="<?php echo ARID; ?>" />
 <input type="hidden" name="id" value="<?php echo $pizza_options['id']; ?>" />
<table width="100%" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td width="150">Name:</td>
    <td><input type="text" name="name" value="<?php echo $pizza_options['name']; ?>" /></td>
  </tr>


        <tr>
    <td width="150">Max Toppings:</td>
    <td><input type="text" name="max_toppings" value="<?php echo $pizza_options['max_toppings']; ?>"  /></td>
  </tr>
    <tr>
    <td width="150">Per Topping Price:</td>
    <td><input type="text" name="topping_price" value="<?php echo $pizza_options['topping_price']; ?>" /></td>
  </tr>
     <tr>
    <td width="150">Discount for pickup:</td>
    <td><input type="text" name="discount"  value="<?php echo $pizza_options['discount']; ?>"  /></td>
  </tr>
       <tr>
    <td width="150">2nd Tier fee:</td>
    <td>Starting at topping # <input type="text" name="tier_amount" value="<?php echo $pizza_options['tier_amount']; ?>" style="width:100px"  /> Add how much? <input style="width:100px" type="text" name="tier_price" value="<?php echo stripslashes($pizza_options['tier_price']); ?>"  /> </td>
  </tr>

  <tr>
    <td width="150">Enable sides</td>
    <td>
    
    <?php
	$sides = unserialize($pizza_options['sides']);

	?>
    
    None<input type="checkbox" name="sides[0]" value="1" <?php if($sides[0] == 1){ echo 'checked="checked"'; }?>style="width:25px"   /> Left<input style="width:25px"  type="checkbox" name="sides[1]"  value="1" <?php if($sides[1] == 1){ echo 'checked="checked"'; }?>  /> Whole<input style="width:25px"  type="checkbox" name="sides[2]" value="1" <?php if($sides[2] == 1){ echo 'checked="checked"'; }?>  /> Right<input style="width:25px"  type="checkbox" name="sides[3]" value="1" <?php if($sides[3] == 1){ echo 'checked="checked"'; }?>  /> </td>
  </tr>
      <tr>
    <td width="150">Enable first free topping:</td>
    <td><input type="checkbox" name="free_topping" value="1" style="width:25px" <?php if($pizza_options['free_topping'] == 1){ echo 'checked="checked"'; }?>   /></td>
  </tr>
  <tr>
 <tr>
   <td>Pizza base bread  (comma seperated)</td>
       <td><textarea name="base"  style="width:600px;height:150px"><?php echo $pizza_options['base']; ?></textarea></td>
  </tr> 
<tr>
    <td>Vegetable Toppings</td>
       <td><textarea name="toppings"  style="width:600px;height:150px"><?php echo $pizza_options['toppings']; ?></textarea></td>
  </tr> 
  <tr>
    <td>Meat Toppings </td>
       <td><textarea name="meat_toppings"  style="width:600px;height:150px"><?php echo $pizza_options['meat_toppings']; ?></textarea></td>
  </tr
  ><tr>
    <td>Final Toppings</td>
       <td><textarea name="topoff"  style="width:600px;height:150px"><?php echo $pizza_options['topoff']; ?></textarea></td>
  </tr>
   <tr>
    <td>&nbsp;</td>
    <td><input type="submit"  value="Save"/></td>
  </tr>
</table></form>


<?php


}

if($_GET['add'] == 1 or ($_GET['id'] != "")){
          
  if($_GET['add'] == 1){
    $method = 'add';	
          
  }else{
    $method = 'edit';	
    $pizza= $database->select("SELECT * FROM pizza_feasts_items where id  = ".$_GET['id']."");
    $pizza_prices = unserialize($pizza[0]['price']);
  }

		
		
  if($pizza[0]['image'] != ''){
echo 'Current Image:<div style="margin:10px;padding:10px"><img src="../UserFiles/Image/product_photos/'.$pizza[0]['image'].'"></div>';	
  }
?>
    
  <form action="../functions/pizza-feasts.php?function=<?php echo $method; ?>-item" method="post" enctype="multipart/form-data">
  <input type="hidden" name="rid" value="<?php echo ARID; ?>" />
  <input type="hidden" name="id" value="<?php echo $pizza[0]['id']; ?>" />
                <table width="85%" border="0" cellspacing="0" cellpadding="0">
  <tr>
        <td><strong>Item Name </strong></td>
        <td><input type="text" name="name" value="<?php echo $pizza[0]['name']; ?>">

        <input type="hidden" name="cat" value="<?php echo $catid; ?>" >
        
        </td>
  </tr>
  <tr>
        <td><strong>Upload Image </strong></td>
        <td><input type="file" name="image" /> 
        
        </td>
  </tr>


  </tr>
          <tr>
        <td><strong>Price </strong></td>
        <td>
  <table width="100%" border="0" cellspacing="5" cellpadding="5">

 

  <tr>
    <td width="75"> Small:</td>
    <td> <input type="text" name="price[]"  value="<?php echo $pizza_prices[0]; ?>"></td>
  </tr>
   <tr>
    <td width="75"> Medium:</td>
    <td> <input type="text" name="price[]"  value="<?php echo $pizza_prices[1]; ?>"></td>
  </tr>
          
          <tr>
    <td width="75"> Large:</td>
    <td> <input type="text" name="price[]"  value="<?php echo $pizza_prices[2]; ?>" /></td>
  </tr>
                           
  </table>

    </td>
  </tr>
  <tr>
    <td >
      <strong>Description:</strong>
    </td>
    <td>
      <div >
        <textarea name="description" cols="45" rows="10"><?php echo $pizza[0]['description']; ?></textarea>
      </div>
    </td>
					
  </tr>
				
  <tr>
    <td></td>
    <td ><input type="submit" name="submit" value="Save"></td>
  </tr>
</table>
</form>

<?php

} else {
  $pizzas = $database->select("SELECT * FROM pizza_feasts_items where rid  = ".ARID."");

  echo '<table width="100%" border="0" cellpadding="4" cellspacing="4">';
  for($i=0; $i<count($pizzas); $i++){
    echo '<tr>
            <td width="80%"  style="border-bottom:1px dashed #52b4e6;padding:5px"><a href="index.php?edit=pizza-feasts&id='.$pizzas[$i]['id'].'&function=edit-item">'.$pizzas[$i]['name'].'</a></td>
            <td  style="border-bottom:1px dashed #52b4e6;padding:5px"><a href="index.php?edit=pizza-feasts&id='.$pizzas[$i]['id'].'&function=edit-item"><img src="application_edit.png" border="0">Edit</a></td>
            <td  style="border-bottom:1px dashed #52b4e6;padding:5px"><a onclick="return confirmDelete(this);"  href="../functions/pizza-feasts.php?function=delete-item&itemid='.$pizzas[$i]['id'].'&mid="><img src="delete.png" border="0">Delete</a></td>
          </tr>';
  } // for
  echo '</table>';
} // else

?>
